package com.briup.jd2511.jd2511_product_source.controller;

import com.briup.jd2511.jd2511_product_source.pojo.ManagerHurdles;
import com.briup.jd2511.jd2511_product_source.result.Result;
import com.briup.jd2511.jd2511_product_source.service.HurdlesService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "栏圈管理模块")
@RestController
@RequestMapping("/hurdle")
public class HurdleController {
    @Autowired
    private HurdlesService hurdlesService;

    @GetMapping
    @Operation(summary = "分页/查询栏圈接口")
    @Parameters(value = {
            @Parameter(name = "pageName",required = true,description = "页码",in = ParameterIn.QUERY),
            @Parameter(name = "pageSize",required = true,description = "每页数量",in = ParameterIn.QUERY),
            @Parameter(name = "hName",description = "栏圈名称",in = ParameterIn.QUERY),
            @Parameter(name = "hMax",description = "栏圈容量",in = ParameterIn.QUERY),
            @Parameter(name = "fhName",description = "栏舍名称",in = ParameterIn.QUERY),
            @Parameter(name = "hEnable",description = "栏圈启用状态",in = ParameterIn.QUERY)
    })
    public Result queryAllByPage(@RequestParam(defaultValue = "1")Integer pageName,
                                 @RequestParam(defaultValue = "10")Integer pageSize,
                                 @RequestParam(required = false)String hName,
                                 @RequestParam(required = false)Integer hMax,
                                 @RequestParam(required = false)String fhName,
                                 @RequestParam(required = false)String hEnable
                                 ){
        PageInfo<ManagerHurdles> pageInfo = hurdlesService.queryAllByPage(pageName,pageSize,hName,hMax,fhName,hEnable);
        return Result.success(pageInfo);
    }

    @GetMapping("/queryAllMax")
    @Operation(summary = "查询所有的栏圈容量")
    public Result queryAllMax(){
        List<Integer> hMaxNum = hurdlesService.findAllMax();
        return Result.success(hMaxNum);
    }

    @PutMapping("/{hId}/{hEnable}")
    @Operation(summary = "修改栏圈启用状态")
    public Result updateHurdleEnable(@PathVariable String hId,@PathVariable String hEnable){
        hurdlesService.updateHurdleEnable(hId,hEnable);
        return Result.success();
    }
    @PutMapping
    @Operation(summary = "批量禁用/启用栏圈状态")
    public Result updateHurdleEnableBatch(@RequestBody List<Map<String,String>> list){
        hurdlesService.updateHEnableBatch(list);
        return Result.success();
    }
    @GetMapping("/queryAllEnable")
    @Operation(summary = "查询所有可用的栏圈")
    public Result queryAllEnable(){
        return Result.success(hurdlesService.queryAllEnable());
    }

//    @PostMapping("/saveOrUpdate")
//    @Operation(summary = "添加/修改栏圈")
//    public Result saveOrUpdate(@RequestBody ManagerHurdles managerHurdles){
//        try{
//            hurdlesService.saveOrUpdate(managerHurdles);
//            return Result.success();
//        }catch (Exception e){
//            return Result.failure(e.);
//        }
//
//    }

}
